$(document).ready(function() {
    $('#register-form').submit(function(event) {
      event.preventDefault();
  
      var uid = $('#uid').val();
      var password = $('#password').val();
  
      if (uid === '' || password === '') {
        alert('请填写用户名和密码！');
        return;
      }
  
      $.ajax({
        type: 'POST',
        url: 'egister.php',
        data: {
          uid: uid,
          password: password
        },
        success: function(data) {
          if (data === '注册成功！') {
            alert('注册成功！');
            window.location.href = 'login.html'; // 跳转到登录页面
          } else {
            alert('注册失败：' + data);
          }
        },
        error: function(xhr, status, error) {
          alert('注册失败：' + error);
        }
      });
    });
  });